package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.XcxRole;
import com.ruoyi.system.service.IXcxRoleService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 小程序角色Controller
 * 
 * @author ruoyi
 * @date 2022-12-29
 */
@Api(tags = "小程序角色模块接口")
@RestController
@RequestMapping("/xcxrole")
public class XcxRoleController extends BaseController
{
    @Autowired
    private IXcxRoleService xcxRoleService;

    /**
     * 查询小程序角色列表
     */
//    @RequiresPermissions("system:xcxrole:list")
    @GetMapping("/list")
    public TableDataInfo list(XcxRole xcxRole)
    {
        startPage();
        List<XcxRole> list = xcxRoleService.selectXcxRoleList(xcxRole);
        return getDataTable(list);
    }

    /**
     * 导出小程序角色列表
     */
    @RequiresPermissions("system:xcxrole:export")
    @Log(title = "小程序角色", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XcxRole xcxRole)
    {
        List<XcxRole> list = xcxRoleService.selectXcxRoleList(xcxRole);
        ExcelUtil<XcxRole> util = new ExcelUtil<XcxRole>(XcxRole.class);
        util.exportExcel(response, list, "小程序角色数据");
    }

    /**
     * 获取小程序角色详细信息
     */
    @RequiresPermissions("system:xcxrole:query")
    @GetMapping(value = "/{xcxRoleId}")
    public AjaxResult getInfo(@PathVariable("xcxRoleId") Long xcxRoleId)
    {
        return success(xcxRoleService.selectXcxRoleByXcxRoleId(xcxRoleId));
    }

    /**
     * 新增小程序角色
     */
    @RequiresPermissions("system:xcxrole:add")
    @Log(title = "小程序角色", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XcxRole xcxRole)
    {
        return toAjax(xcxRoleService.insertXcxRole(xcxRole));
    }

    /**
     * 修改小程序角色
     */
    @RequiresPermissions("system:xcxrole:edit")
    @Log(title = "小程序角色", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XcxRole xcxRole)
    {
        return toAjax(xcxRoleService.updateXcxRole(xcxRole));
    }

    /**
     * 删除小程序角色
     */
    @RequiresPermissions("system:xcxrole:remove")
    @Log(title = "小程序角色", businessType = BusinessType.DELETE)
	@DeleteMapping("/{xcxRoleIds}")
    public AjaxResult remove(@PathVariable Long[] xcxRoleIds)
    {
        return toAjax(xcxRoleService.deleteXcxRoleByXcxRoleIds(xcxRoleIds));
    }
}
